/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.asiainfo.utils.sql.sqlbuilder.delete;

import java.util.Collection;
import java.util.LinkedList;
import org.apache.commons.lang3.StringUtils;

public class DeleteQuery {
	private final String table;
	private Collection<String> wheres;

	public DeleteQuery(String table) {
		this.table = table;
		this.wheres = new LinkedList();
	}

	public DeleteQuery addWhere(String where) {
		this.wheres.add(where);
		return this;
	}

	public String toString() {
		StringBuilder result = new StringBuilder();

		result.append("DELETE FROM ").append(this.table);

		if (!(this.wheres.isEmpty())) {
			result.append(" WHERE ").append(StringUtils.join(this.wheres, " AND "));
		}

		return result.toString();
	}
}